package net.ithe.service.impl;

import net.ithe.mapper.ClazzMapper;
import net.ithe.mapper.EmpMapper;
import net.ithe.mapper.StudentMapper;
import net.ithe.pojo.ClazzOption;
import net.ithe.pojo.JobOption;
import net.ithe.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper  empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;

    /**
     * 查询员工学历数据
     * @return
     */
    @Override
    public List<Map<String, Object>> getDegreeData() {
        return studentMapper.countDegreeData();
    }
    /**
     * 查询班级人数数据
     * @return
     */
    @Override
    public ClazzOption getClazzOption() {
        List<Map<String, Object>> studentCountData=clazzMapper.countStudentData();
        if(studentCountData!=null){
            List<Object> clazzList=studentCountData.stream().map(dataMap ->dataMap.get("name")).toList();
            List<Object> dataList=studentCountData.stream().map(dataMap ->dataMap.get("total")).toList();
            return new ClazzOption(clazzList,dataList);
        }
        return null;
    }

    @Override
    public JobOption getEmpJobData() {
        //1.调用mapper接口，查询职位数据
        List<Map<String, Object>> list=empMapper.countEmpJobData();

        //2.封装JobOption对象，返回
         List<Object> jobList=list.stream().map(dataMap ->dataMap.get("pos")).toList();
         List<Object> dataList=list.stream().map(dataMap ->dataMap.get("num")).toList();
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
       return empMapper.countEmpGenderData();
    }
}
